<?php 

class Silk_Tms_Block_Adminhtml_Deliver_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
	const ROLE_PARENT_ID = 368;

	public function __construct()
	{
		parent::__construct();
		$this->setId("deliverGrid");
		$this->setDefaultSort("id");
		$this->setDefaultDir("DESC");
		$this->setSaveParametersInSession(true);
	}

	protected function getWebSiteId()
	{
		$session = Mage::getSingleton('admin/session');
		return $session->getUser()->getWebsiteId();
	}

	protected function _prepareCollection()
    {
    	$collection = Mage::getModel('admin/user')->getCollection();
    	$collection->getSelect()->join(array('ar' => 'admin_role'), 'main_table.user_id = ar.user_id And ar.parent_id = ' . self::ROLE_PARENT_ID . ' And main_table.is_active And main_table.website_id = ' . $this->getWebSiteId());

    	$this->setCollection($collection);
        return parent::_prepareCollection();
    }

    public function getItemCollection()
    {
        $this->_prepareCollection();
        return $this->setCollection();
    }

    protected function _prepareColumns()
	{
		$this->addColumn("user_id", array(
			"header" => Mage::helper("tms")->__("ID"),
			"align" =>"right",
			"width" => "50px",
		    "type" => "number",
			"index" => "user_id",
		));

		$this->addColumn("username", array(
			"header" => Mage::helper("zgb")->__("用户名"),
			"index" => "username",
		));

		$this->addColumn("firstname", array(
			"header" => Mage::helper("zgb")->__("姓氏"),
			"index" => "firstname",
		));

		$this->addColumn("lastname", array(
			"header" => Mage::helper("zgb")->__("名字"),
			"index" => "lastname",
		));

		$this->addColumn("phone", array(
			"header" => Mage::helper("zgb")->__("联系电话"),
			"index" => "phone",
		));

		return parent::_prepareColumns();
	}

	protected function _prepareMassaction()
	{
		$this->setMassactionIdField('id');
		$this->getMassactionBlock()->setFormFieldName('ids');
		$this->getMassactionBlock()->setUseSelectAll(true);
		$this->getMassactionBlock()->addItem('bind_warehouse', array(
			'label' => Mage::helper('tms')->__('分配'),
			'url' => $this->getUrl('*/adminhtml_shipping/shippingbind'),
		));
		return $this;
	}
}